<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>订单详情</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../../mui/css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../../../css/app.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/icons-extra.css" />

	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">订单详情</h1>
		</header>
		<footer>
			<div class="mui-row">
				<div class="footer-item mui-col-xs-4 ">
				</div>
				<div class="footer-item mui-col-xs-4 mui-text-right">
					<button type="button" class="mui-btn mui-btn-outlined ">取消订单</button>
				</div>
				<div class="footer-item mui-col-xs-4 ">
					<button type="button" class="mui-btn mui-btn-warning">立即下单</button>
				</div>
			</div>
		</footer>
		<div class="mui-content" style="margin: 0px auto 60px auto;">
			<ul class="mui-table-view mui-table-view-chevron">
				<div id="addressDiv"></div>
			</ul>

			<ul class="mui-table-view order-detail-view" >
				<div id="orderDetailDiv"></div>
			</ul>
			<ul class="mui-table-view mui-table-view-chevron">
				<li class="mui-table-view-cell mui-media">
					<a class='mui-navigate-right' href="#payTypeDiv">
						<div class="mui-row">
							<div class="mui-col-xs-6">
								<p>支付方式</p>
							</div>
							<div class="mui-col-xs-6">
								<p class="mui-text-right">
									<font color="#000000" id="payType">微信支付</font>
								</p>
							</div>
						</div>
					</a>
				</li>
			
			</ul>

			<ul class="mui-table-view">
				<li class="mui-table-view-cell">
					<div class="mui-row">
						<div class="mui-col-xs-6">
							<p>商品总额</p>
						</div>
						<div class="mui-col-xs-6" id="totalAmountDiv">
						</div>
					</div>
				</li>
				<li class="mui-table-view-cell">
					<div class="mui-row">
						<div class="mui-col-xs-6">
							<p>+运费</p>
						</div>
						<div class="mui-col-xs-6" id="transportDiv">
						</div>
					</div>
					<ul class="mui-table-view content-list" >
						<div id="payAmountDiv">
						</div>
					</ul>
				</li>
			</ul>
		</div>
		<div id="payTypeDiv" class="mui-popover mui-popover-action mui-popover-bottom" style="z-index: 99999;">
			<ul class="mui-table-view">
				<li class="mui-table-view-cell">
					<a href="#">微信支付</a>
				</li>
				<li class="mui-table-view-cell">
					<a href="#">支付宝支付</a>
				</li>
				<li class="mui-table-view-cell">
					<a href="#">银联支付</a>
				</li>
			</ul>
			
		</div>
	</body>
	<script src="../../../mui/js/mui.min.js"></script>
	<script src="../../../js/jquery-2.1.1.min.js"></script>
	<script src="../../../js/common.js"></script>
	<script src="../../../js/ajax-common.js"></script>	
	<script type="text/javascript" charset="utf-8">
		mui.init({
			swipeBack: true //启用右滑关闭功能
		});
		
		mui.ready(function(){
			var goodsId = window.localStorage.selectGoodsId;
			var url = "order/create";
			var data = {
				goodsIds:goodsId
			};
			var success = function(response) {
				var order = response.order;
				/*设置订单信息*/
				setOrderInfo(order);
				window.localStorage.orderNo = order.orderNo;
			};
			ajaxFunc(url, data, success);
		})
		
		/*设置订单信息*/
		function setOrderInfo(order){
			/*设置收货地址*/
			var addressHtml = "";
			if(!order.address){
				addressHtml = '<li class="mui-table-view-cell mui-media"><p>请设置收货地址</p></li>'
			}else{
			 	addressHtml = '<li class="mui-table-view-cell mui-media"><a class="mui-navigate-right" href="address.html"><p><span class="mui-icon mui-icon-location"></span><font color="#000000">'+order.consignee+
					order.mobileNo+'</font></p><textarea class="index-textarea" readhttp://192.168.16.126:8020/eshop-wechat/view/eshop/order/invoice.htmlonly="readonly">'+order.address+'</textarea></a></li>';
				$('#addressDiv').html(addressHtml);
			}
			/*设置商品详情*/
			var orderDetailHtml ="";
			if(order.orderDetails){
				console.log(JSON.stringify(order.orderDetails));
				for(key in order.orderDetails){
					orderDetailHtml = orderDetailHtml + setOrderDetailList(order.orderDetails[key]);
				}
			}
			$('#orderDetailDiv').html(orderDetailHtml);
			
			/*设置订单信息*/
			var amountHtml = '<p class="mui-text-right"><font color="#ff0000">￥'+order.totalAmount+'</font></p>';
			$('#totalAmountDiv').html(amountHtml);
			var transportHtml = '<p class="mui-text-right"><font color="#ff0000">￥'+'</font></p>';
			$('#transportDiv').html(transportHtml);
			var payAmountHtml = '<h4 class="mui-text-right">实付款：<font color="#ff0000">'+order.payAmount+'￥</font></h4><h5 class="mui-text-right">'+ Format(new Date(order.orderTime),"yyyy-MM-dd HH:mm")+'</h5>';
			$('#payAmountDiv').html(payAmountHtml);
			
		}
		/*设置商品列表*/
		function setOrderDetailList(orderDetail){
			var goodHtml = "";
			goodHtml = '<li class="mui-table-view-cell"><img class="order-image mui-pull-left" src="'+'"><div class="mui-media-body"><a id= "'+orderDetail.goodsId+'"><textarea class="index-textarea" readonly="readonly">'+
			orderDetail.goodsName+'</textarea><p class="mui-text-right">'+orderDetail.price+'</p></a></div></li>';
			return goodHtml;
		}
		
		/*商品列表点击跳转页面 */
		mui(".order-detail-view").on('tap', 'a', function() {
			var goodsId = this.getAttribute('id');
			console.log("goodsId="+goodsId);
			mui.openWindow({
				id:'goodsDetail',
				url:'../goods/goodsDetail.html',
			});
			window.localStorage.goodsId = goodsId; 
		});
		
		/*支付方式跳着页面*/
		/*document.getElementById("payTypeDiv").addEventListener("tap",function(){
			
			mui.openWindow({
				id:'payType',
				url:'../pay/payType.html'
			});
		});*/
		
		mui('body').on('tap', '.mui-popover-action li>a', function() {
			var a = this,
				parent;
			//根据点击按钮，反推当前是哪个actionsheet
			for (parent = a.parentNode; parent != document.body; parent = parent.parentNode) {
				if (parent.classList.contains('mui-popover-action')) {
					break;
				}
			}
			//关闭actionsheet
			mui('#' + parent.id).popover('toggle');
			var payType = document.getElementById("payType");
			payType.innerHTML = a.innerHTML;
			//console.log(a.innerHTML);
			
		})
	</script>

</html>